<html>
<head>
<title>GPTL usage example 5: Fortran use of gptlprocess_namelist() to set GPTL options</title>
<meta name="example" content="gptlprocess_namelist Fortran">
<meta name="Keywords" content="gptl","papi","call tree","profile","timing","performance analysis">
<meta name="Author" content="Jim Rosinski">
</head>
<body bgcolor="peachpuff">

<hr />
<a href="example4.html"><img border="0" src="btn_previous.gif"
				  width="100" height="20" alt="Example 4"
				  /></a> 
<a href="example6.html"><img border="0" src="btn_next.gif"
			     width="100" height="20" alt="Example 6" /></a>

<a href="index.html">Back to GPTL home page</a>

<br />

<h2>Example 5: Fortran use of gptlprocess_namelist() to set GPTL options</h2>
This example is a Fortran code which uses convenience
function <b>gptlprocess_namelist()</b> to set <b>GPTL</b> options instead of inserting
calls to <b>gptlsetoption()</b> into the application code. The main advantage
to this approach is that it avoids having to recompile and relink the
application code when changing GPTL options.
<p>
<b><em>nlreader.F90:</em></b>
<pre>
<div style="background-color:white;">
program nlreader
  use gptl

  implicit none

  integer :: ret

  ret = gptlsetoption (gptlverbose, 1)
  write(6,*)'nlreader: Testing gptlprocess_namelist...'
  call gptlprocess_namelist ('gptlnl', 1, ret)
  if (ret /= 0) then
    write(6,*)'Failure'
    call exit (1)
  end if
      
  ! Now turn off verbosity

  ret = gptlsetoption (gptlverbose, 0)
  ret = gptlinitialize ()
  ret = gptlstart ('main')
  ret = gptlstop ('main')
  ret = gptlpr (0)
  write(6,*)'Success'
end program nlreader
</div>
</pre>
Next are the contents of the namelist file. Note that <em>verbose = 1</em>,
which results in printout when each namelist variable is set. The namelist
group name must always be <em>gptlnl</em>. The equivalent library call is
commented next to each namelist setting.
<p>
<b><em>gptlnl:</em></b>
<pre>
<div style="background-color:white;">
&gptlnl
! These settings are all the opposite of the default
 wall            = .false.   ! gptlsetoption (gptlwall,0)
 cpu             = .true.    ! gptlsetoption (gptlcpu,1)
 abort_on_error  = .true.    ! gptlsetoption (gptlabort_on_error,1)
 overhead        = .true.    ! gptlsetoption (gptloverhead,1)
 depthlimit      = 5         ! gptlsetoption (gptldepthlimit,5)
 verbose         = .true.    ! gptlsetoption (gptlverbose,1)
 percent         = .true.    ! gptlsetoption (gptlpercent,1)
! Comment out persec and multiplex so "nlreader" test won't fail even if 
!   PAPI unavailable
! persec          = .false.  ! gptlsetoption (gptlpersec,0)
! multiplex       = .true.   ! gptlsetoption (gptlmultiplex,1)
 dopr_preamble   = .false.   ! gptlsetoption (gptldopr_preamble,0)
 dopr_threadsort = .false.   ! gptlsetoption (gptldopr_threadsort,0)
 dopr_multparent = .false.   ! gptlsetoption (gptldopr_multparent,0)
 dopr_collision  = .false.   ! gptlsetoption (gptldopr_collision,0)

! utr, print_method, and eventlist use character variables instead of integer 
! to avoid "magic number" settings in the namelist

 utr             = 'nanotime'     ! gptlsetutr (gptlnanotime)
 print_method    = 'full_tree'    ! gptlsetoption (gptlprintmethod, gptlfull_tree)
!print_method    = 'first_parent' ! gptlsetoption (gptlprintmethod, gptlfirst_parent)
!print_method    = 'last_parent'  ! gptlsetoption (gptlprintmethod, gptllast_parent)
!print_method    = 'most_frequent'! gptlsetoption (gptlprintmethod, gptlmost_frequent)

! List of events to count. PAPI_FP_OPS is a PAPI event, and GPTL_CI is a
! PAPI-based derived event.
! Comment out eventlist so "nlreader" test won't fail even if PAPI unavailable
! eventlist       = 'PAPI_FP_OPS','GPTL_CI'
/
</div>
</pre>
Now compile and run:
<pre>
<div>
% gfortran nlreader.F90 -o nlreader -I${GPTL}/include -I${GPTL}/lib -lgptlf -lgptl
% ./nlreader
</div>
</pre>

Here's the output:
<pre>
<div style="background-color:white;">
GPTLsetoption: boolean verbose = 1
GPTLsetoption: boolean abort_on_error = 1
GPTLsetoption: boolean wallstats = 0
GPTLsetoption: cpustats = 1
GPTLsetoption: depthlimit = 1
GPTLsetoption: boolean percent = 1
GPTLsetoption: boolean dopr_preamble = 0
GPTLsetoption: boolean dopr_threadsort = 0
GPTLsetoption: boolean dopr_multparent = 0
GPTLsetoption: boolean dopr_collision = 0
GPTLsetutr: underlying wallclock timer = nanotime
GPTLsetoption: print_method = full_tree
 gptlprocess_namelist: skipping check for PAPI-based events because GPTL was built without PAPI support
</div>
</pre>
<h3>Explanation of the above output</h3>
Each namelist setting results in a call to <b>GPTLsetoption()</b>
or <b>GPTLsetutr()</b> with the listed value. The output appears
because <em>verbose</em> was set to true.
<hr />
<a href="example4.html"><img border="0" src="btn_previous.gif"
				  width="100" height="20" alt="Example 4"
				  /></a> 
<a href="example6.html"><img border="0" src="btn_next.gif"
			     width="100" height="20" alt="Example 6" /></a>

<a href="index.html">Back to GPTL home page</a>

<br />

</html>
